//
//  WZDiscoverSearchView.swift
//  weiBo---01
//
//  Created by 王—wagn on 16/4/6.
//  Copyright © 2016年 王—wagn. All rights reserved.
//

import UIKit

class WZDiscoverSearchView: UIView {

    @IBOutlet weak var textView: UITextField!
    
    @IBOutlet weak var candleBtn: UIButton!
  
    @IBOutlet weak var rightCon: NSLayoutConstraint!
    
    
    override func awakeFromNib() {
        
        self.frame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: self.bounds.height)
        
        //设置左侧小图
        self.textView.leftView = UIImageView(image: UIImage(named:"searchbar_textfield_search_icon"))
        self.textView.leftView?.frame = CGRect(x: 0, y: 0, width: self.bounds.height, height: self.bounds.height)
        
        //设置图片显示位置
        self.textView.leftView?.contentMode = .Center
        
        //设置始终显示
        self.textView.leftViewMode = .Always
        
    }
 
    class func loadSearchView() -> WZDiscoverSearchView {
        let v = NSBundle.mainBundle().loadNibNamed("WZDiscoverCell", owner:nil, options:nil ).last as! WZDiscoverSearchView
        
        return v
    }
    
    //点击方法是did begin
    
    @IBAction func textSearchDid(sender: AnyObject) {
        
        rightCon.constant = candleBtn.frame.width
        
        UIView.animateWithDuration(0.26) { () -> Void in
            
            self.layoutIfNeeded()
        }
    }
    
    @IBAction func candleBtnDidClick(sender: AnyObject) {
        textView.resignFirstResponder()
        
        rightCon.constant = 0
        
        UIView.animateWithDuration(0.25) { () -> Void in
            self.layoutIfNeeded()
        }
    }
    
}
